/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { ProColumns } from '@ant-design/pro-table';
import TableOperate from '@base/components/ProTableExtend/operate';
import { dateCalendar } from '@base/utils';
import React from 'react';
import Status, { createStatusOptions } from './status';

export interface ColumnItem {
  print_type: string;
  print_style: string;
  print_code: string;
  send_time: string;
  style_name: string;
  print_name: string;
  selling_time: string;
  get_time: string;
  desc: string;
  status: string;
  id: string;
}

export function useCreateColumns() {
  const columns: ProColumns<ColumnItem>[] = [
    {
      dataIndex: 'print_name',
      title: '类型',
      search: false,
    },
    {
      dataIndex: 'style_name',
      title: '打印机款式',
      search: false,
    },
    {
      dataIndex: 'print_code',
      title: '打印机编码',
      copyable: true,
    },
    {
      dataIndex: 'send_time',
      title: '赠送时长',
      search: false,
      render: (text) => {
        return `${text}个月`;
      },
    },
    {
      dataIndex: 'selling_time',
      title: '售卖时间',
      search: false,
      renderText: (val) => dateCalendar(val),
    },
    {
      dataIndex: 'get_time',
      title: '领取时间',
      search: false,
      renderText: (val) => dateCalendar(val),
    },
    {
      dataIndex: 'desc',
      title: '备注',
      search: false,
    },
    {
      dataIndex: 'status',
      title: '状态',
      valueType: 'select',
      fieldProps: {
        placeholder: '全部',
        options: createStatusOptions(),
      },
      renderText: (val) => <Status value={val} />,
    },
    {
      dataIndex: 'id',
      title: '操作',
      fixed: 'right',
      width: 100,
      search: false,
      render: (_, entity, __, action) => {
        const { status } = entity;
        const options =
          status == '0'
            ? [{ name: '删除', key: 'delete', withConfirm: true }]
            : status == '1'
            ? [{ name: '撤销', key: 'revoke', withConfirm: true }]
            : null;
        return <TableOperate<ColumnItem> options={options} data={entity} action={action as any} />;
      },
    },
  ];

  return columns;
}
